import utils from "../../utils/utils.js"
const state = {
    token: null,
	tel:'',
    admin:{},
	userInfo:{},
    type:'',
	openId:'',
	roleCode:'',
    menu:[],
    introduction: '',
}

const mutations = {
    //设置版本信息数据
    SET_USERINFO: (state, userInfo) => {
        state.userInfo = userInfo
    },
	//设置版本信息数据
	SET_TYPE: (state, type) => {
	    state.type = type
	},
	SET_OPENID: (state, openId) => {
	    state.openId = openId
	},
	SET_TOKEN: (state, token) => {
	    state.token = token
	},
	SET_TEL: (state, tel) => {
	    state.tel = tel
	},
	SET_ROLE_CODE: (state, roleCode) => {
		state.roleCode = roleCode
	},
}

const actions = {
    //复制token信息
	// 获取用户信息
	setTokenInfo({commit}) {
	    return new Promise((resolve, reject) => {
			let token = utils.getCacheData("authorization");
			commit('SET_TOKEN', token)
			resolve()
	    })
	},
	setTel({commit},tel) {
	    return new Promise((resolve, reject) => {
			commit('SET_TEL', tel)
			resolve()
	    })
	},
	loginOut({commit}){
		commit('SET_TOKEN', null)
		utils.removeStorageSync("authorization");
		uni.reLaunch({
			url:"/pages/login/index"
		})
	},
	setUserInfo({commit},userInfo){
		commit('SET_USERINFO', userInfo)
	},
	setRoleCode({commit},roleCode){
		commit('SET_ROLE_CODE', roleCode)
	}
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}